
public class MyQueue {
    static class Node{
        public int val;
        public Node next;

        public Node(int val) {
            this.val = val;
        }
    }
    public Node head;
    public Node Last;
    public int UsedSize;

    public void add(int val){
        Node node = new Node(val);
        if (isEmpty()){
            head = node;
            Last = node;
        }else {
            Last.next = node;//将新节点与原链表建立链接
            Last = node;//将新节点设为Last
        }
        UsedSize++;
    }
    public int pull() {
        if (isEmpty()) {
            return -1;
        }
        int cur = head.val;
        head = head.next;
        //出队后要进行判断：此时队列是否为空？
        if (head == null){
            Last = null;
        }
        UsedSize--;
        return cur;
    }
    public int peek(){
        int cur;
        if (isEmpty()) {
            return -1;
        } else {
            cur = head.val;
        }
        return cur;
    }
    public int getUsedSize(){
        return UsedSize;
    }
    public boolean isEmpty(){
        if (UsedSize == 0){
            return true;
        }
        return false;
    }
}
